#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
    ios_base::sync_with_stdio(false);cin.tie(nullptr);
    int T; cin >> T;
    for (int k = 1; k <= T; ++k) {
        cout << "Case #" << k << ": ";
        ll N, s1, v1, s2, v2;
        cin >> N >> s1 >> v1 >> s2 >> v2;
        ll ans = 0;
        const int div = 1e4;
        if(s1 > div){
            for (int t1 = 0; t1 <= N/s1; ++t1) {
                ll t2 = (N-t1*s1)/s2;
                ans = max(ans, t1*v1 + t2*v2);

            }
        }else if(s2 > div){
            for (int t2 = 0; t2 <= N/s2; ++t2) {
                ll t1 = (N-t2*s2)/s1;
                ans = max(ans, t1*v1 + t2*v2);
            }
        }else{
            if(v1*s2 > v2*s1){
                for (int t2 = 0; t2 < s1 && t2 <= N/s2; ++t2) {
                    ll t1 = (N-t2*s2)/s1;
                    ans = max(ans, t1*v1 + t2*v2);

                }
            }else{
                for (int t1 = 0; t1 < s2 && t1 <= N/s1; ++t1) {
                    ll t2 = (N-t1*s1)/s2;
                    ans = max(ans, t1*v1 + t2*v2);
                }
            }
        }

        cout << ans << "\n";
    }

    return 0;

}